<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
	<script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>

</head>

<body class="hold-transition skin-red sidebar-mini" >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">商品审核</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
                                        <button type="button" class="btn btn-default" title="审核通过" onclick="auditYes()"><i class="fa fa-check"></i> 审核通过</button>
                                        <button type="button" class="btn btn-default" title="驳回" onclick="auditNo()"><i class="fa fa-ban"></i> 驳回</button>
                                        <button type="button" class="btn btn-default" title="刷新" ><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
                            <div class="box-tools pull-right">
                                <div class="has-feedback">
                                    商品名称：<input id="name">
									<button onclick="listGoods()"  class="btn btn-default" >查询</button>
                                </div>
                            </div>
                            <!--工具栏/-->

			                  <!--数据列表-->
			                  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
			                      <thead>
			                          <tr>
			                              <th class="" style="padding-right:0px">
			                                  <input id="selall" type="checkbox" class="icheckbox_square-blue">
			                              </th> 
										  <th class="sorting_asc">商品ID</th>
									      <th class="sorting">商品名称</th>
									      <th class="sorting">商品价格</th>
									      <th class="sorting">一级分类</th>
									      <th class="sorting">二级分类</th>
									      <th class="sorting">三级分类</th>
									      <th class="sorting">状态</th>									     						
					                      <th class="text-center">操作</th>
			                          </tr>
			                      </thead>
			                      <tbody id="goodsShow">

			                      </tbody>
			                  </table>
			                  <!--数据列表/-->
							<form id="page">

								<a href="javascript:toPage(1)">首页</a>
								<a href="javascript:toPage(2)">上一页</a>
								第<input type="text"  id="pageNum" size="1px" readonly="readonly">页/
								共<input type="text" id="pages" size="1px" disabled="disabled">页/
								共<input type="text" id="total" size="1px" disabled="disabled">条
								<a href="javascript:toPage(3)">下一页</a>
								<a href="javascript:toPage(4)">尾页</a>
							</form>
							 
                        </div>
                        <!-- 数据表格 /-->
                        
                        
                     </div>
                    <!-- /.box-body -->
        
</body>
<script>
	function auditYes(){
		if(confirm("是否通过审核")){
			var ids = []  //定义一个数组
			$("[type=checkbox]").each(function (i, e) {   //获取所有复选框的value,循环
				if ($(e).prop("checked")) {   //判断是否被选中
					ids.push($(e).val())  //选中就添加到数组中
				}
			})
			$.ajax({
				url: "/goods/auditYes?ids=" + ids,
				type: "get",
				dataType: "json",
				async: false,
				success: function (result) {
					if (result.code == "666") {
						alert(result.message)
						listGoods()
					} else {
						alert(result.message)
					}
				},
				error: function (){
					alert("系统异常")
				}
			})
		}
	}
	function auditNo(){
        if(confirm("是否不通过审核")){
            var ids = []  //定义一个数组
            $("[type=checkbox]").each(function (i, e) {   //获取所有复选框的value,循环
                if ($(e).prop("checked")) {   //判断是否被选中
                    ids.push($(e).val())  //选中就添加到数组中
                }
            })
            $.ajax({
                url: "/goods/auditNo?ids=" + ids,
                type: "get",
                dataType: "json",
                async: false,
                success: function (result) {
                    if (result.code == "666") {
                        alert(result.message)
                        listGoods()
                    } else {
                        alert(result.message)
                    }
                },
                error: function (){
                    alert("系统异常")
                }
            })
        }
	}


	$(function (){
		listGoods();
	})
	function listGoods(num){
		$.ajax({
			url: "/goods/listGoods",
			data: {pageNum:num,pageSize:10,name:$("#name").val()},
			type: "get",
			dataType: "json",
			async:false,
			success: function (result) {
				if(result.code == "666"){
					var goods = result.data.rows
					var html = ""
					for (var i = 0; i < goods.length; i++) {
						html += '<tr>'
						html += '<td><input value="'+ goods[i].id +'" type="checkbox"></td>'
						html += '<td>'+ goods[i].id +'</td>'
						html += '<td>'+ goods[i].goodsName +'</td>'
						html += '<td>'+ goods[i].price +'</td>'
						html += '<td>'+ goods[i].category1Name +'</td>'
						html += '<td>'+ goods[i].category2Name +'</td>'
						html += '<td>'+ goods[i].category3Name +'</td>'
						html += '<td>'
						var s = '未审核'
						if(goods[i].auditStatus == "1"){
							 s = '审核通过'
						}
						if(goods[i].auditStatus == "2"){
							 s = '审核驳回'
						}
						html += '<span>'
						html += s
						html += '</span>'
						html += '</td>'
						html += '<td className="text-center">'
						html += '<button type="button" className="btn bg-olive btn-xs">详情</button>'
						html += '</td>'
						html += '</tr>'
					}
					$("#goodsShow").html(html);
					// 分页
					$("#pageNum").val(result.data.pageNum);
					$("#pages").val(result.data.pages);
					$("#total").val(result.data.total);
				}else{
					$("#goodsShow").html("<tr><td>" + result.message + "</td></td></tr>");
				}

			},
			error: function (){
				alert("系统异常")
			}
		})
	}
	//分页
	function toPage(id){
		var num = parseInt($("#pageNum").val());
		var pages = parseInt($("#pages").val());
		var p = num;
		if (id == 1) {
			p = 1;
			$("#pageNum").val(1);
		}
		if (id == 2){
			if (num == 1) {
				alert("已经到达首页了");
				return;
			}
			p = num - 1;
			$("#pageNum").val(num - 1);
		}
		if (id == 3){
			if (num == pages) {
				alert("已经到达尾页了");
				return;
			}
			p = num + 1;
			$("#pageNum").val(num + 1);
		}
		if (id==4){
			p = pages;
			$("#pageNum").val(pages);
		}
		listGoods(p);
	}
</script>
</html>